{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Joy Ride - Part 3: Parallel Parking\n",
    "In this section you will write a function that implements the correct sequence of steps required to parallel park a vehicle.\n",
    "\n",
    "**Note** for this segment the vehicle's maximum speed has been set to just over 4 mph. This should make parking a little easier.\n",
    "\n",
    "![](https://upload.wikimedia.org/wikipedia/commons/2/26/ParallelParkingAnimation.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"buttonStyle.css\">\n",
       "<button id=\"launcher\">Launch Car Simulator</button>\n",
       "<button id=\"restart\">Restart Connection</button>\n",
       "<script src=\"setupLauncher.js\"></script>\n",
       "<script src=\"kernelRestart.js\"></script>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%HTML\n",
    "<link rel=\"stylesheet\" type=\"text/css\" href=\"buttonStyle.css\">\n",
    "<button id=\"launcher\">Launch Car Simulator</button>\n",
    "<button id=\"restart\">Restart Connection</button>\n",
    "<script src=\"setupLauncher.js\"></script>\n",
    "<script src=\"kernelRestart.js\"></script>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'src'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-c68e9893c347>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     33\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mcar_parameters\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     34\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 35\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0msrc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msimulate\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0msim\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     36\u001b[0m \u001b[0msim\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcontrol\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'src'"
     ]
    }
   ],
   "source": [
    "# After running any code changes make sure to click the button \"Restart Connection\" above first.\n",
    "# Also make sure to click Reset in the simulator to refresh the connection.\n",
    "\n",
    "car_parameters = {\"throttle\": 0, \"steer\": 0, \"brake\": 0}\n",
    "def control(pos_x, pos_y, time, velocity):\n",
    "    \"\"\" Controls the simulated car\"\"\"\n",
    "    global car_parameters\n",
    "    if(pos_y > 37.6):\n",
    "        car_parameters[\"throttle\"] = -0.2\n",
    "        car_parameters[\"steer\"] = 1\n",
    "        car_parameters[\"brake\"] = 0\n",
    "    elif(pos_y > 35):\n",
    "        car_parameters[\"throttle\"] = -0.01\n",
    "        car_parameters[\"steer\"] = 0\n",
    "        car_parameters[\"brake\"] = 0\n",
    "    elif(pos_y > 31.5):\n",
    "        car_parameters[\"throttle\"] = -0.01\n",
    "        car_parameters[\"steer\"] = -1\n",
    "        car_parameters[\"brake\"] = 0\n",
    "    else:\n",
    "        car_parameters[\"throttle\"] = 0\n",
    "        car_parameters[\"steer\"] = 0\n",
    "        car_parameters[\"brake\"] = 1\n",
    "\n",
    "    # TODO: Use WASD keys in simulator to gain an intuitive feel of parallel parking.\n",
    "    # Pay close attention to the time, position, and velocity in the simulator.\n",
    "    \n",
    "    # TODO: Use this information to make decisions about how to set your car parameters\n",
    "    \n",
    "    # In this example the car will drive forward for three seconds\n",
    "    # and then backs up until its y_pos is less than 32 then comes to a stop by braking\n",
    "   \n",
    "    return car_parameters\n",
    "    \n",
    "import src.simulate as sim\n",
    "sim.run(control)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Submitting this Project!\n",
    "Your parallel park function is \"correct\" when:\n",
    "\n",
    "1. Your car doesn't hit any other cars.\n",
    "2. Your car stops completely inside of the right lane.\n",
    "\n",
    "Once you've got it working, it's time to submit. Submit by pressing the `SUBMIT` button at the lower right corner of this page."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
